<template>
  <div class="app-container">
    <!-- 基本信息 -->
    <div class="titleLineGreen flexbet">
      基本信息
      <el-button
        v-preventReClick
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        >添加备注</el-button
      >
    </div>
    <el-table v-loading="loading" :data="[shopInfo]" style="margin-top: 10px">
      <el-table-column label="订单编号" align="center" prop="orderNo">
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="门店"
        align="center"
        prop="schoolNames"
      >
      </el-table-column>
      <el-table-column label="生效时间" align="center" prop="startDate">
      </el-table-column>
      <el-table-column label="有效期至" align="center" prop="endDate">
      </el-table-column>
      <el-table-column label="订单金额(元)" align="center" prop="amount">
      </el-table-column>
    </el-table>
    <!-- 课程信息 -->
    <div class="titleLineGreen" style="margin-top: 20px">课程信息</div>
    <div class="tableTopLine">课程信息</div>
    <div class="tableContain flex">
      <div
        v-for="(item, index) in courseList"
        :key="index"
        class="tableContain_item flex"
        :style="{ width: courseList.length == 1 ? '100%' : '50%' }"
      >
        <div class="item_cover">
          <el-image :src="item.coursePic"></el-image>
        </div>
        <div class="item_info">
          <div class="item_title overtxt">
            {{ item.courseName }}
          </div>
          <div class="item_author overtxt">
            {{ item.creatorName }}
          </div>
        </div>
      </div>
    </div>
    <!-- 操作信息 -->
    <div class="titleLineGreen" style="margin-top: 20px">操作信息</div>
    <el-table
      v-loading="loading"
      :data="operationInfoList"
      style="margin-top: 10px"
    >
      <!-- <el-table-column
        show-overflow-tooltip
        label="操作"
        align="center"
        prop="schoolName"
      >
      </el-table-column> -->
      <el-table-column label="操作" align="center" prop="operation">
      </el-table-column>
      <el-table-column label="操作人" align="center" prop="createByName">
      </el-table-column>
      <el-table-column label="操作时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <div>
            {{ parseTime(scope.row.createTime) }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark">
      </el-table-column>
    </el-table>
    <el-button
      style="position: fixed; bottom: 20px; right: 20px"
      v-preventReClick
      type="primary"
      @click="back()"
      >返回</el-button
    >
    <div style="height: 100px"></div>

    <!-- 添加或修改岗位对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      title="添加备注"
      :visible.sync="open"
      width="500px"
      append-to-body
    >
      <el-form
        @submit.native.prevent
        ref="form"
        :model="form"
        :rules="rules"
        label-width="50px"
      >
        <el-form-item label="备注" prop="remark">
          <el-input
            v-input-restrict
            style="width: 95%"
            v-model="form.remark"
            type="textarea"
            placeholder="请输入备注"
            maxlength="500"
            show-word-limit
            :autosize="{ minRows: 5, maxRows: 8 }"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-preventReClick @click="cancel">取 消</el-button>
        <el-button v-preventReClick type="primary" @click="submitForm"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
  
<script>
import { getPost_order, addPost_remark } from "@/api/order/order";
export default {
  props: {},
  data() {
    return {
      loading: false,
      //   基本信息
      shopInfo: {
        id: 1,
        schoolName: "北京大学",
      },
      //   门店信息
      courseList: [1, 2],
      //   操作信息
      operationInfoList: [],
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        remark: [{ required: true, message: "备注不能为空", trigger: "blur" }],
      },
    };
  },
  watch: {},
  methods: {
    back() {
      this.$router.go(-1);
      this.$tab.closePage();
    },
    async getPost_order() {
      this.loading = true;
      const res = await getPost_order(this.$route.query.id);
      this.courseList = res.data.courseList;
      this.shopInfo = res.data.order;
      res.data.remarkList.map((item) => {
        item.operation = "添加备注";
      });
      res.data.remarkList.unshift({
        operation: "提交订单",
        createByName: res.data.order.createByName,
        createTime: res.data.order.createTime,
        remark: res.data.order.remark ? res.data.order.remark : "--",
      });
      this.operationInfoList = res.data.remarkList;
      this.loading = false;
    },
    handleAdd() {
      this.reset();
      this.open = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: this.$route.query.id,
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          addPost_remark(this.form).then((response) => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getPost_order();
          });
        }
      });
    },
  },
  created() {},
  mounted() {
    /* 获取订单信息 */
    this.getPost_order();
  },
};
</script>
  <style scoped lang="scss">
.tableTopLine {
  text-align: center;
  margin-top: 10px;
  height: 44px;
  line-height: 44px;
  font-size: 13px;
  color: #515a6e;
  font-weight: bold;
  background: rgba(229, 229, 229, 0.2);
  border-bottom: 1px solid #ebeef5;
}
.tableContain {
  .tableContain_item:nth-of-type(2n) {
    border-left: 1px solid #ebeef5;
  }
  .tableContain_item {
    padding: 10px 10px;
    border-bottom: 1px solid #ebeef5;
    box-sizing: border-box;
    .item_cover {
      width: 160px;
      height: 100px;
    }
    .item_info {
      margin: 0px 0 0 10px;
      flex: 1;
      overflow: hidden;
      .item_title {
        font-size: 16px;
        font-weight: 600;
      }
      .item_author {
        margin-top: 5px;
        font-size: 14px;
        font-weight: 400;
      }
    }
  }
}
</style>
  